<%@ page language="java" contentType="text/html; charset=utf-8"
	import="daoimpl.*,dao.*,java.util.*,bean.*,factory.*"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="sun.security.smartcardio.SunPCSC.Factory"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>模块管理</title>
</head>
<%
	ModuleDao dao = new ModuleDaoImpl();
	List<Module> list = dao.queryAll();
%>
<body>
<table align="center">
	<tr>
		<td><input type="button" value="模块管理"
			onclick="window.location.href='/module.jsp'" /></td>
		<td><input type="button" value="功能点管理"
			onclick="window.location.href='/function.jsp'" /></td>
	</tr>
</table>

<table align="center">
	<tr>
		<td><input type="button" value="增加模块"
			onclick="addModule.style.display='';updateModule.style.display='none';" /></td>
	</tr>
</table>

<form action="">
<table id="addModule" align="center" style="display: none;">
	<tr>
		<td>模块名</td>
		<td><input type="text" /></td>
		<td><input type="submit" value="提交" /></td>
	</tr>
</table>
</form>

<script type="text/javascript" language="javascript">
window.onload = function() {
	var str_url = window.location.href;
	var str_pos = str_url.indexOf("?");
	var str_para = str_url.substring(str_pos + 1);
	var arr_param = new Array();
	var module_id = "";
	if (str_pos > 0) {
		arr_param = str_para.split("&");
		for ( var i = 0; i < arr_param.length; i++) {
			var temp_str = new Array()
			temp_str = arr_param[i].split("=")
			if (temp_str[0] === 'module_id') {
				module_id = temp_str[1];
			}
		}
	}
	//alert(module_id);
	if(module_id){
		var module = document.getElementById("module");
		module.value=module_id;
		document.getElementById("module_id").value=module_id;
		document.getElementById("module_name").value=module.options[module.selectedIndex].label;
		document.getElementById("mm_name").innerHTML=module.options[module.selectedIndex].label;
		
	}
}
function getModule(obj){
	window.location.href = "/module.jsp?module_id="+obj.value;
	return false;
}
function tijiao(type){
	var form = document.getElementById("form");
	if(type==1){
		document.getElementById("module_type").value="1";
	}else if(type==2){
		document.getElementById("module_type").value="2";
	}else{
	}
	form.submit();
	return false;
}
</script>

<form id="form" action="/result.jsp">
<table id="updateModule" align="center" style="display: ;">
	<tr>
		<td align="right">请选择模块:</td>
		<td>
			<select id="module" onchange="getModule(this)">
				<%
					for(int i=0; i<list.size(); i++){
						Module m = list.get(i);
				%>
					<option label="<%=m.getModule_name() %>" value="<%=m.getModule_id() %>"></option>
				<%
					}
				%>
			</select>
		</td>
		<td></td>
		<td></td>
	</tr>
	<tr>
		<%
			int id = 0;
			String name = ""; 
			if(request.getParameter("module_id")!=null){
				id = Integer.parseInt(request.getParameter("module_id").toString());
			}
			if(list!=null&&list.size()>0){
				if(id == list.get(0).getModule_id()){
					name = list.get(0).getModule_name();
				}
			}else{
				id=0;
				name = "";
			}  
		%>
		<td align="right">
			<input id="module_id" type="hidden" name="module_id" value="<%=id%>"/>
			<input id="module_type" type="hidden" name="module_type" value="0"/>
		模块名:</td>
		<td><input name="module_name" type="text" value="<%=name %>"/></td>
		<td><input type="button" value="修改" onclick="tijiao(1);"/></td>
		<td><input type="button" value="删除" onclick="tijiao(2);" /></td>
	</tr>

	<tr>
		<td align="center" colspan="2">
		<span id="mm_name">
		</span>
		<span>=></span>
		</td>
		<td align="center" colspan="2">
		<%
			List<FunctionPoint> functionList = DaoFactory.getFunctionPointDaoInstance().queryFunctionPointByModule(new Module(id));
			for(int i=0;i<functionList.size();i++){
		%>
		<a href="/function.jsp?id=<%=functionList.get(i).getFunctionPoint_id() %>"><%=functionList.get(i).getFunctionPoint_name() %></a><br />
		<%
			} 
		%>
		</td>
	</tr>

</table>
</form>
</body>
</html>